<{extends "../Layout/default.html"}>
<{block name="main"}>
<{if !empty($errors)}>
<div class="weui-toptips weui-toptips_warn" style="display: block;"><{$errors[0]}></div>
<{/if}>
<div class="carousel">
    <img src="/img/banner.jpg" />
</div>
<form method="post" action="/user/input">
    <div class="formpage">
        <{foreach $authitem as $k => $val}>
        <section>
            <header class="weui-cells__title"><{if $k == 'base'}>基本信息<{else}>认证信息<{/if}></header>
            <div class="weui-cells weui-cells_form">
                <{foreach $val as $key => $row}>
                <{if $row.item_type == 1}>
                <div class="weui-cell  weui-cell_select weui-cell_select-after">
                    <div class="weui-cell__hd">
                        <label class="weui-label weui-label-6em"><{$row.item_name}>:</label>
                    </div>
                    <div class="weui-cell__bd">
                        <select class="weui-select brand-select" name="data[brand]">
                            <{foreach $brand as $b}>
                            <option data-id="<{$b.id}>" value="<{$b.name}>" <{if $b.name == $data.brand || $b.name == $user.brand}>selected="selected"<{/if}>><{$v}><{$b.name}></option>
                            <{/foreach}>
                        </select>
                    </div>
                </div>
                <{else if $row.item_type == 2}>
                <div class="weui-cell  weui-cell_select weui-cell_select-after">
                    <div class="weui-cell__hd">
                        <label class="weui-label weui-label-6em"><{$row.item_name}>:</label>
                    </div>
                    <div class="weui-cell__bd">
                        <select class="weui-select model-select" name="data[model]">

                        </select>
                    </div>
                </div>
                <{else if $row.item_type == 3}>
                <div class="weui-cell">
                    <div class="weui-cell__hd">
                        <label class="weui-label weui-label-6em"><{$row.item_name}>:</label>
                    </div>
                    <div class="weui-cell__bd">
                        <input class="weui-input" type="text" <{if $row.item_field == 'mobile'}>readonly<{/if}> name="data[<{$row.item_field}>]" value="<{if $row.item_field == 'mobile'}><{$mobile}><{else}><{if $data[$row.item_field]}><{$data[$row.item_field]}><{else}><{$user[$row.item_field]}><{/if}><{/if}>" placeholder="<{$row.item_val}>">
                    </div>
                </div>
                <{else if $row.item_type == 4}>
                <div class="weui-cell  weui-cell_select weui-cell_select-after">
                    <div class="weui-cell__hd">
                        <label class="weui-label weui-label-6em"><{$row.item_name}>:</label>
                    </div>
                    <div class="weui-cell__bd">
                        <select class="weui-select" name="data[<{$row.item_field}>]">
                            <{foreach $row.item_val_list as $k => $v}>
                            <option value="<{$v}>" <{if $v == $data[$row.item_field] || $v == $user[$row.item_field]}>selected="selected"<{/if}>><{$v}></option>
                            <{/foreach}>
                        </select>
                    </div>
                </div>
                <{else if $row.item_type == 5}>
                <div class="weui-cell weui-cell_select weui-cell_select-after weui-cell_input_after">
                    <div class="weui-cell__hd">
                        <label for="" class="weui-label weui-label-6em"><{$row.item_name}>:</label>
                    </div>
                    <div class="weui-cell__bd input-mask-p">
                        <input class="input-mask" type="date" data-target="#<{$row.item_field}>">
                        <input class="weui-input" type="text" name="data[<{$row.item_field}>]" value="<{if $data[$row.item_field]}><{$data[$row.item_field]}><{else}><{$user[$row.item_field]}><{/if}>" placeholder="<{$row.item_val}>" id="<{$row.item_field}>">
                    </div>
                </div>
                <{/if}>
                <{/foreach}>
            </div>
        </section>
        <{/foreach}>
        <div class="weui-btn-area">
            <input type="hidden" name="complete" value="1">
            <input type="submit" class="weui-btn weui-btn_primary" id="">
        </div>
    </div>
</form>
<script>
    $(".input-mask").on("change", function () {
        var id = $(this).data("target");
        $(id).val($(this).val());
    });
    var brand = $.parseJSON('<{$brand|@json_encode}>');
    var model = $.parseJSON('<{$model|@json_encode}>');
    var umVal = '<{$user.model}>';
    var dmVal = '<{$data.model}>';
    var brandSelect = $('.brand-select');
    var modelSelect = $('.model-select');
    $(function () {
        changeBrand(true);
        brandSelect.change(function () {
            changeBrand(false);
        })
    });
    function changeBrand(init) {
        if (model.length > 0) {
            var html = '';
            for (var i = 0; i < model.length; i++) {
                if (model[i].brand_id == brandSelect.find('option:checked').data('id')) {
                    if ((model[i].name == umVal || model[i].name == dmVal) && init == true) {
                        html += '<option selected="selected" value="' + model[i].name + '">' + model[i].name + '</option>';
                    } else {
                        html += '<option value="' + model[i].name + '">' + model[i].name + '</option>'
                    }
                }
            }
            modelSelect.html(html);
        }
    }
</script>
<{/block}>